package com.phiture.erp.basic.web.controller.api;

import com.phiture.erp.basic.api.pojo.resp.ErpCustomerResp;
import com.phiture.erp.basic.api.service.ErpCustomerApi;
import com.phiture.erp.basic.core.service.ErpCustomerService;
import com.phiture.erp.basic.dal.entity.ErpCustomerDO;
import com.phiture.erp.basic.web.convert.ErpCustomerConvertMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;

/**
 * @author YH
 * @date 2025/4/8
 */
@Service
@RequiredArgsConstructor
public class ErpCustomerApiServiceImpl implements ErpCustomerApi {
    private final ErpCustomerService erpCustomerService;

    @Override
    public ErpCustomerResp validateCustomer(Long id) {
        ErpCustomerDO erpCustomerDO = erpCustomerService.validateCustomer(id);
        return ErpCustomerConvertMapper.INSTANCE.toErpCustomerResp(erpCustomerDO);
    }

    @Override
    public Map<Long, ErpCustomerResp> getCustomerMap(Collection<Long> ids) {
        List<ErpCustomerDO> customerList = erpCustomerService.getCustomerList(ids);
        List<ErpCustomerResp> list = ErpCustomerConvertMapper.INSTANCE.toErpCustomerRespList(customerList);
        return convertMap(list, ErpCustomerResp::getId);
    }
}
